package com.zx.sdk.util;

import com.zx.sdk.league.member.BaseLeagueMember;
import com.zx.sdk.league.member.BeiZi;
import com.zx.sdk.league.member.DuoMeng;
import com.zx.sdk.league.member.JiGuang;
import com.zx.sdk.league.member.JiGuangBid;
import com.zx.sdk.league.member.JiaJi;
import com.zx.sdk.league.member.KS;
import com.zx.sdk.league.member.MTG;
import com.zx.sdk.league.member.QQ;
import com.zx.sdk.league.member.Ta;
import com.zx.sdk.league.member.WangMai;
import com.zx.sdk.league.member.XunFei;
import com.zx.sdk.league.member.YouTui;
import com.zx.sdk.league.member.baidu.BaiDu;
import com.zx.sdk.league.member.sigmob.Sigmob;
import com.zx.sdk.league.member.zhongjian.ZhongJian;

import java.util.HashMap;

/*广告联盟成员管理器*/
public class LeagueMemberHelper {
    private static final HashMap<String, BaseLeagueMember<?, ?, ?, ?, ?>> MEMBERS = new HashMap<>();

    static {
        MEMBERS.put("qq", new QQ());
        MEMBERS.put("ks", new KS());
        MEMBERS.put("sig", new Sigmob());
        MEMBERS.put("bd", new BaiDu());
        MEMBERS.put("mtg", new MTG());
        MEMBERS.put("jg", new JiGuang());
        MEMBERS.put("jgbid", new JiGuangBid());
        MEMBERS.put("zj", new ZhongJian());
        MEMBERS.put("beizi", new BeiZi());
        MEMBERS.put("xunfei", new XunFei());
        MEMBERS.put("jiaji", new JiaJi());
        MEMBERS.put("wm", new WangMai());
        MEMBERS.put("dm", new DuoMeng());
        MEMBERS.put("yt", new YouTui());
        MEMBERS.put("ta", new Ta());
    }

    public static BaseLeagueMember<?, ?, ?, ?, ?> getMember(String name) {
        if (StringHelper.isEmpty(name) || !MEMBERS.containsKey(name)) {
            return MEMBERS.get("ks");
        }

        return MEMBERS.get(name);
    }

    /**
     * 当前是否支持这个联盟
     *
     * @param name 联盟名缩写
     */
    public static boolean isSupportLeague(String name) {
        return MEMBERS.containsKey(name);
    }

    public static void foreach(Iterator iterator) {
        for (String key : MEMBERS.keySet()) {
            iterator.onIterate(MEMBERS.get(key));
        }
    }

    public interface Iterator {
        void onIterate(BaseLeagueMember<?, ?, ?, ?, ?> member);
    }
}
